#! /bin/tcsh -f
#------------------------------------------------
# Author:    kvkrishna
# Created:   Tue Jan 26 13:22:47 IST 2011
# File Name: New
# Usage:
#       New interpr FileName [#! flags]
# 
# 
#------------------------------------------------
alias die 'echo "\!:2-$" ; exit \!:1'
#------------------------------------------------
if ($# < 2) then
        die 8 "ERROR: Improper argument list" 
endif
which $1 >& /dev/null
if ( $? ) then
        die 1 "$1 : Command not found"
endif
#------------------------------------------------
set Interpr = `which $1` ;      shift 
set NewFile = $1 ;              shift 
#------------------------------------------------
if (-e $NewFile) then
        die 8 "ERROR: File exists"
else
        touch $NewFile ; chmod +x $NewFile
endif
#------------------------------------------------
echo "#! $Interpr $*"                                                                   >> $NewFile
echo "#------------------------------------------------"                                >> $NewFile
echo "# Author:    $USER"                                                               >> $NewFile
echo "# Created:   `date`"                                                              >> $NewFile
echo "# File Name: $NewFile:t"                                                          >> $NewFile
echo "# USAGE: "                                                                        >> $NewFile
echo "#       $NewFile:t "                                                              >> $NewFile
echo "# "                                                                               >> $NewFile
echo "# "                                                                               >> $NewFile
echo "#------------------------------------------------"                                >> $NewFile
echo ""                                                                                 >> $NewFile
#------------------------------------------------
if (! $?EDITOR ) then
        setenv EDITOR gvim
endif
$EDITOR $NewFile
